package com.jctrip.hotel.source.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.jctrip.hotel.source.model.Result;
import com.jctrip.hotel.source.model.hworld.req.HworldAddOrderReq;
import com.jctrip.hotel.source.model.hworld.req.HworldCancelOrderReq;
import com.jctrip.hotel.source.model.hworld.req.HworldCheckAvailabilityReq;
import com.jctrip.hotel.source.model.hworld.req.HworldGetCardInfoReq;
import com.jctrip.hotel.source.model.hworld.resp.*;
import com.jctrip.hotel.source.model.wehotel.req.OrderData;
import com.jctrip.hotel.source.service.hworld.HworldService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Api(tags = "hworld")
@RestController
@RequestMapping("/hworld")
@ApiSupport(order = 7)
public class HworldController {
    @Resource
    private HworldService hworldService;

    @GetMapping("/getHotelList")
    @ApiOperation(value = "getHotelList", notes = "获取酒店列表")
    @ApiOperationSupport(order = 1)
    public Result getHotelList(@RequestParam(value = "appId", required = false) String appId,
                               @RequestParam(value = "key", required = false) String key) {
        List<HworldHotelInfo> result;
        try {
            result = hworldService.getHotelList(appId, key);
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
        return Result.ok(result);
    }

    @GetMapping("/getHotelComplexList")
    @ApiOperation(value = "getHotelComplexList", notes = "获取酒店基础信息&房型")
    @ApiOperationSupport(order = 2)
    public Result getHotelComplexList(@RequestParam(value = "appId", required = false) String appId,
                                      @RequestParam(value = "key", required = false) String key,
                                      @RequestParam(value = "hotelId", required = false) String hotelId) {
        List<HworldHotelDetail> result;
        try {
            result = hworldService.getHotelComplexList(appId, key, hotelId);
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
        return Result.ok(result);
    }

    @GetMapping("/getHotelRoomType")
    @ApiOperation(value = "getHotelRoomType", notes = "获取酒店房型")
    @ApiOperationSupport(order = 3)
    public Result getHotelRoomType(@RequestParam(value = "appId", required = false) String appId,
                                   @RequestParam(value = "key", required = false) String key,
                                   @RequestParam(value = "hotelId", required = false) String hotelId) {
        List<HworldHoteRoomType> result;
        try {
            result = hworldService.getHotelRoomType(appId, key, hotelId);
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
        return Result.ok(result);
    }


    @GetMapping("/getTMCRoomPrice")
    @ApiOperation(value = "查询会员房态", notes = "查询会员房态")
    @ApiOperationSupport(order = 4)
    public Result getTMCRoomPrice(@RequestParam(value = "appId", required = false) String appId,
                                  @RequestParam(value = "key", required = false) String key,
                                  @RequestParam(value = "hotelId", required = false) String hotelId,
                                  @RequestParam(value = "start", required = false) String start,
                                  @RequestParam(value = "end", required = false) String end,
                                  @RequestParam(value = "roomTypeCode", required = false) String roomTypeCode,
                                  @RequestParam(value = "memberLevel", required = false) String memberLevel) {
        HworldRoomDTO result;
        try {
            result = hworldService.getTMCRoomPrice(appId, key, hotelId, start, end, roomTypeCode, memberLevel);
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
        return Result.ok(result);
    }

    @GetMapping("/getTMCAllRoomPrice")
    @ApiOperation(value = "查询会员和活动房态", notes = "查询会员和活动房态")
    @ApiOperationSupport(order = 4)
    public Result getTMCAllRoomPrice(@RequestParam(value = "appId", required = false) String appId,
                                     @RequestParam(value = "key", required = false) String key,
                                     @RequestParam(value = "hotelId", required = false) String hotelId,
                                     @RequestParam(value = "start", required = false) String start,
                                     @RequestParam(value = "end", required = false) String end,
                                     @RequestParam(value = "roomTypeCode", required = false) String roomTypeCode,
                                     @RequestParam(value = "memberLevel", required = false) String memberLevel) {
        List<HworldRoomDTO> result;
        try {
            result = hworldService.getTMCAllRoomPrice(appId, key, hotelId, start, end, roomTypeCode, memberLevel);
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
        return Result.ok(result);
    }

    @GetMapping("/getActivityRuleList")
    @ApiOperation(value = "查询活动价接口", notes = "查询活动价接口")
    @ApiOperationSupport(order = 4)
    public Result getActivityRuleList(@RequestParam(value = "appId", required = false) String appId,
                                      @RequestParam(value = "key", required = false) String key) {
        List<HworldActivityRuleListResult> result;
        try {
            result = hworldService.getActivityRuleList(appId, key);
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
        return Result.ok(result);
    }

    @PostMapping("/checkAvailability")
    @ApiOperation(value = "checkAvailability", notes = "checkAvailability")
    @ApiOperationSupport(order = 5)
    public Result checkAvailability(@RequestParam(value = "appId", required = false) String appId,
                                    @RequestParam(value = "key", required = false) String key,
                                    @RequestBody HworldCheckAvailabilityReq req) {
        HworldCheckAvailabilityDTO result;
        try {
            result = hworldService.checkAvailability(appId, key, req);
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
        return Result.ok(result);
    }

    @PostMapping("/addOrder")
    @ApiOperation(value = "addOrder", notes = "创建订单")
    @ApiOperationSupport(order = 6)
    public Result addOrder(@RequestParam(value = "appId", required = false) String appId,
                           @RequestParam(value = "key", required = false) String key,
                           @RequestBody HworldAddOrderReq req) {
        String result;
        try {
            result = hworldService.addOrder(appId, key, req);
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
        return Result.ok(result);
    }

//    @GetMapping("/postOrder")
//    @ApiOperation(value = "postOrder", notes = "下单")
//    @ApiOperationSupport(order = 7)
//    OrderDataResult postOrder(String appId, String key, HworldAddOrderReq req, PriceCheckParam priceCheck){
//        return hworldService.postOrder(appId, key, req, priceCheck);
//    }

    @GetMapping("/queryOrderData")
    @ApiOperation(value = "queryOrderData", notes = "查询订单")
    @ApiOperationSupport(order = 8)
    public Result queryOrderData(@RequestParam(value = "appId", required = false) String appId,
                                 @RequestParam(value = "key", required = false) String key,
                                 @RequestParam(value = "orderId", required = false) String orderId) {
        OrderData result;
        try {
            result = hworldService.queryOrderData(appId, key, orderId);
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
        return Result.ok(result);
    }

    @PostMapping("/cancelOrder")
    @ApiOperation(value = "cancelOrder", notes = "取消订单")
    @ApiOperationSupport(order = 9)
    public Result cancelOrder(@RequestParam(value = "appId", required = false) String appId,
                              @RequestParam(value = "key", required = false) String key,
                              @RequestBody HworldCancelOrderReq req) {
        Boolean result;
        try {
            result = hworldService.cancelOrder(appId, key, req);
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
        return Result.ok(result);
    }


    //================接口直连================
    @GetMapping("/queryOrderDetail")
    @ApiOperation(value = "queryOrderDetail", notes = "接口直连查询订单详情")
    public Result queryOrderDetail(@RequestParam(value = "sourceId") String sourceId,
                                   @RequestParam(value = "orderId") @ApiParam(value = "订单编号") String orderId) {
        HworldOrderInfo hworldOrderInfo;
        try {
            hworldOrderInfo = hworldService.queryByRequestNo(sourceId, orderId);
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
        return Result.ok(hworldOrderInfo);
    }

    //获取卡等级信息
    @PostMapping("/getCardInfo")
    @ApiOperation(value = "getCardInfo",notes = "查询卡等级信息")
    public Result getCardInfo(@RequestParam(value = "appId")String appId,
                              @RequestParam(value = "key")String key,
                              @RequestBody(required = false)List<String> bookerIds) {
        List<HworldCardInfo> cardInfoList;
        try{
            cardInfoList = hworldService.getCardInfo(appId, key, bookerIds);
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
        return Result.ok(cardInfoList);
    }
}
